//
//  FHYModel.m
//  Education
//
//  Created by jxyeagle on 14-8-13.
//  Copyright (c) 2014年 姬鑫宇. All rights reserved.
//

#import "FHYModel.h"

@implementation FHYModel

+ (instancetype)sharedFHYModel
{
    static FHYModel * _model = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _model = [[FHYModel alloc]init];
        _model.version = DotaVersion;
//        _model.client = DotaClient;
    });
    
    return _model;
    
}

+ (NSDictionary *)comParametersConfigration
{
    
    NSMutableDictionary * dict = [[NSMutableDictionary alloc]initWithCapacity:0];
//    [dict setValue:EducationModel.version forKey: @"version"];
//    [dict setValue:EducationModel.client forKey:@"client"];
//    [dict setValue:@"iPhone客户端" forKey:@"source"];
//    //    [dict setValue:DotaModel.userId forKey:@"userId"];
//    if (EducationModel.jsession) {
//        [dict setValue:EducationModel.jsession forKey:@"jsession"];
//    }
//    else {
//        [dict setValue:@" " forKey:@"jsession"];
//    }
    return dict;
}


+ (AFHTTPRequestOperation *)loginWithBlock:(void(^)(BOOL result, FHYLogInModel* userDic,NSString* failedMessage,NSError* error))block withUserName:(NSString *)userName password:(NSString *)password
{
    NSMutableDictionary * dict = [[NSMutableDictionary alloc]initWithCapacity:0];
    [dict setObject:@"true" forKey:@"json"];
    [dict setObject:password forKey:@"j_password"];
    [dict setObject:userName forKey:@"j_username"];
    
    return [[AFAppDotNetAPIClientIOS6 sharedClient] GET:@"j_spring_security_check" parameters:dict success:^(AFHTTPRequestOperation *operation, id responseObject){
        NSLog(@"URL = %@",operation.request);
        
        NSString * response = [[NSString alloc]initWithData:responseObject encoding:NSUTF8StringEncoding];
        BOOL result = NO;
        NSDictionary * responseDict = [response objectFromJSONString];
        NSDictionary * resultDic = [responseDict objectForKey:@"data"];
        FHYLogInModel *model = [[FHYLogInModel alloc] initWithDictionary:resultDic error:nil];
        if (![[resultDic objectForKey:@"msg"] isEqualToString:@"登陆成功"]) {
            if (block) {
                block(result,model,[resultDic objectForKey:@"msg"],nil);
            }
        }else {
            if (block) {
                block(!result,model,[resultDic objectForKey:@"msg"],nil);
            }
            
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        DLog(@"%@",error);;
        if (block) {
            block(NO,nil,nil,error);
        }
    }];
}

+ (AFHTTPRequestOperation *)testingWithBlock:(void(^)(BOOL result, NSArray* testArray,NSError* error))block
{
    return [[AFAppDotNetAPIClientIOS6 sharedClient] GET:@"app/exam/examuser/Arrangemobile/listIng.do" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject){
        NSLog(@"URL = %@",operation.request);
        
        NSString * response = [[NSString alloc]initWithData:responseObject encoding:NSUTF8StringEncoding];
        BOOL result = NO;
        NSDictionary * responseDict = [response objectFromJSONString];
        NSArray * array = [responseDict objectForKey:@"data"];
        NSMutableArray *mutableArray = [[NSMutableArray alloc]initWithCapacity:0];
        if (array.count) {
            result = YES;
        }
        for (int i = 0; i<array.count; i++) {
            FHYTestModel *model = [[FHYTestModel alloc] initWithDictionary:[array objectAtIndex:i] error:nil];
            [mutableArray addObject:model];
        }
        if (block) {
            block(result,mutableArray,nil);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        DLog(@"%@",error);;
        if (block) {
            block(NO,nil,error);
        }
    }];
}

+ (AFHTTPRequestOperation *)endTestingWithBlock:(void(^)(BOOL result, NSArray* testArray,NSError* error))block
{
    return [[AFAppDotNetAPIClientIOS6 sharedClient] GET:@"app/exam/examuser/Arrangemobile/listEnd.do" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject){
        NSLog(@"URL = %@",operation.request);
        
        NSString * response = [[NSString alloc]initWithData:responseObject encoding:NSUTF8StringEncoding];
        BOOL result = NO;
        NSDictionary * responseDict = [response objectFromJSONString];
        NSArray * array = [responseDict objectForKey:@"data"];
        NSMutableArray *mutableArray = [[NSMutableArray alloc]initWithCapacity:0];
        if (array.count) {
            result = YES;
        }
        for (int i = 0; i<array.count; i++) {
            FHYTestModel *model = [[FHYTestModel alloc] initWithDictionary:[array objectAtIndex:i] error:nil];
            [mutableArray addObject:model];
        }
        if (block) {
            block(result,mutableArray,nil);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        DLog(@"%@",error);;
        if (block) {
            block(NO,nil,error);
        }
    }];
}

+ (AFHTTPRequestOperation *)infoTestingWithBlock:(void(^)(BOOL result, FHYTestInfoModel* infoTest,NSError* error))block
{
    return [[AFAppDotNetAPIClientIOS6 sharedClient] GET:@"app/exam/examuser/Arrangemobile/info.do" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject){
        NSLog(@"URL = %@",operation.request);
        
        NSString * response = [[NSString alloc]initWithData:responseObject encoding:NSUTF8StringEncoding];
        BOOL result = NO;
        NSDictionary * responseDict = [response objectFromJSONString];
        FHYTestInfoModel *model = [[FHYTestInfoModel alloc] initWithDictionary:[responseDict objectForKey:@"data"] error:nil];

        if (block) {
            block(result,model,nil);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        DLog(@"%@",error);;
        if (block) {
            block(NO,nil,error);
        }
    }];
}

@end

@implementation FHYLogInModel

@end

@implementation FHYTestModel

@end

@implementation FHYTestInfoModel


@end